import { getResourceListByCondNoPage } from '@/api/resource';
import { useRequest } from '@jl/common/composable';
import { IPageConfig } from '@jl/element-plus';
export function useList() {
  const formData = ref({
    blurName: '',
    dataType: '',
  });

  const checkBoxArr = ref([]);
  const isThumbnail = ref(false);
  const pageConfig = ref<IPageConfig>({
    small: false,
    visible: true,
    total: 0,
    pageSize: 10,
    currentPage: 1,
    background: true,
  });
  // 获取数据
  const { run, data, loading } = useRequest<any, any>(getResourceListByCondNoPage, {
    list: [],
    count: 0,
  });
  const count = ref(0);
  const search = async (params?: any) => {
    const searchParam = {
      params: {
        blurName: formData.value.blurName,
        categoryId: 'c1b21120-60f6-418e-a6d5-4146442d1b24',
        beginTime: '',
        endTime: '',
        dataType: formData.value.dataType || 'all',
        ...params,
      },
    };
    await run(searchParam);
    checkBoxArr.value = [];
    count.value = data.value.count || 0;
  };
  const toggleChange = () => {
    isThumbnail.value = !isThumbnail.value;
  };
  const tableData = computed(() => {
    return data.value.list.map((v: any, i: number) => ({
      ...v,
      checkbox: false,
      // serial: (pageConfig.value.currentPage - 1) * pageConfig.value.pageSize + i + 1,
    }));
  });
  return { formData, isThumbnail, checkBoxArr, toggleChange, search, tableData, count, loading };
}
